import java.util.ArrayList;
import java.util.Arrays;


public class Main {
	public static int[] genFreqSeq(int[] set) {
		Arrays.sort(set);
		int[] res = new int[set[set.length-1]- set[0]+1]; 
		for (int i = 0; i < set.length; i++) {
			for (int j = i+1; j < set.length; j++) {
				res[set[j]- set[i]]++;
			}
		}
		if (res[0] > 0) {
			System.err.println("input not a set!");
			return null;
		}
		return res;
	}
	
	public static int[] power2s(int n) {
		int[] res = new int[n];
		for (int i = 0; i < n; i++) {
			res[i] = 1<<i;
		}
		return res;
	}
	
	
	public static void printDiffSet(ArrayList<Integer> os) {
		try {
			for (int i = os.size() -1; i >=0;i--) {
				for (int j = 0; j<= i; j++) {
					int count = 0;
					for (int k = j; k <= i; k++) {
						count += os.get(k);
					}
					System.out.format("%5d", count);
				}
				System.out.println();
			}
		}catch (NullPointerException e){
			//Alg didn't succeed
			System.out.println("Algorithm haven't found result!");
		}
		
	}
	

	public static void main(String[] args) {
		
		
		int[] freqencyseq =	//new int[]{0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
							//genFreqSeq(power2s(14));
						  	genFreqSeq(new int[]{2, 3, 5, 7, 11//, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47,53, 59, 61, 67, 71
						  		});
							//genFreqSeq(new int[]{1, 2, 6,});
						
		Structure s = new Structure(freqencyseq);
	
		long start = System.currentTimeMillis();
		//PyramidAlg t = new PyramidAlg(s.DiffSet);
		 DescendAlg t = new DescendAlg(s.DiffSet);
		long stop = System.currentTimeMillis();
		System.out.println(((double)(stop - start)/1000)+" seconds");
		
		//printDiffSet(s.FreqToDif(s.FreqSeq));
		printDiffSet(t.OriginalSet);
		
	}
		
}
